"""AdminUserSeedTableSeeder Seeder."""

from masoniteorm.seeds import Seeder
from app.models.AdminUser import AdminUser
from app.traits.MyModelTrait import MyModelTrait


class AdminUserTableSeeder(Seeder):
    def run(self):
        """Run the database seeds."""
        admin_role_id   = 0
        is_lock         = 0
        is_deleted      = 0
        index           = {'account': 0, 'password': 1, 'nickname': 2}
        users           = [
            ['myadmin', 'myadmin', 'super_admin'],
        ]

        for user in users:
            admin = AdminUser.where('account', user[index['account']]).first()
            if admin is not None:
                print("{0} 已存在".format(user[index['account']]))
                continue

            print("{0} 写入成功".format(user[index['account']]))
            salt     = MyModelTrait.generate_salt(6)
            password = MyModelTrait.generate_password(user[index['password']], salt)
            AdminUser.generate_log(user[index['account']], password, salt, user[index['nickname']], admin_role_id, is_lock, is_deleted)
